from django.contrib.auth.models import Group, Permission
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from apps.meiduo_admin.serializers.groups import GroupSerializer
from apps.meiduo_admin.serializers.permissions import PermissionSerializer
from apps.meiduo_admin.utils import UserPageNum


class GroupView(ModelViewSet):
    '''
        分组权限表的增删改查
    '''
    # 指定查询集
    queryset = Group.objects.all()
    # 指定序列化器
    serializer_class = GroupSerializer
    # 指定分页器
    pagination_class = UserPageNum
    # 指定权限
    permission_classes = [IsAdminUser]

    # 获取简单权限信息
    def simple(self, reqeust):
        pers = Permission.objects.all()
        ser = PermissionSerializer(pers, many=True)
        return Response(ser.data)
